
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>资讯列表</title>
<style type="text/css">
#user_fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
}
</style>


<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/color.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>

</head>
<body >

<div class="tableFind">
        <p>
           <label>资讯标题</label>&nbsp;&nbsp;
				<input type="text" id="infoTitle"  onkeydown="if(event.keyCode==13) searchMessage()"/> 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<!--   <label>发布作者</label>&nbsp;&nbsp;
				<input type="text" id="infoAuthor"  onkeydown="if(event.keyCode==13) searchMessage()"/> 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
		
            
            <a id="btn"
					href="javascript:searchInfo()" class="easyui-linkbutton tableFindBut"
					data-options="iconCls:'icon-search'" onclick="obj.find()">查询	
			  </a>
		</p>
        </div>

     <table id="user_dg" class="easyui-datagrid" style="height: 470px;"
		url="${pageContext.request.contextPath}/admin/Info/findAll.do" toolbar="#user_toolbar" pagination="true"
		rownumbers="true" fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>
		
		<!-- 管理表格-表头的修改 -->
			<tr>
			<th field="cb" checkbox="true" align="center"></th>
            <th field="infoNo" width="80" align="center">资讯编号</th>
            <th field="infoAuthor" width="80" align="center">发布作者</th>
            <th field="infoType" width=150 align="center">资讯类型</th>
            <th field="infoTitle" width="150" align="center">资讯标题</th>
            <th field="infoContent" width="150" align="center">资讯内容</th>
            <th field="publishTime" width="150" align="center">发布时间</th>
			</tr>
		</thead>
	</table>
	<div id="user_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newUserMessage()">新增</a>  <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyUserMessage()">删除</a>
	</div>
	<div id="user_dlg" class="easyui-dialog" style="padding: 10px 20px";
		closed="true" buttons="#user_dlg-buttons">
		<div class="ftitle">详细信息</div>
		<form id="user_fm" method="post" novalidate>
			<div class="fitem">
				<label>发布作者:</label> <input name="infoAuthor" class="easyui-textbox"
					required="true">
			</div>
			<div class="fitem">
				<label>资讯类型:</label> <input name="infoType" class="easyui-textbox"
					required="true">
			</div>
			
			<div class="fitem">
				<label>资讯标题:</label> <input name="infoTitle" class="easyui-textbox"
					required="true">
			</div>
			<div class="fitem">
				<label>资讯内容:</label> <input name="infoContent" class="easyui-textbox">
			</div>
			<div class="fitem">
				<label>发布时间:</label> <input name="publishTime" class="easyui-datebox"
					validType="date">
			</div>
		</form>
	</div>
	<div id="user_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveUserMessage()" style="width: 90px">保存</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#user_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	<script type="text/javascript">
	
	function searchInfo(){
		var infoTitle = $.trim($('#infoTitle').val());		//获取搜索框的内，$.trim()可以消除前后空格
		var infoAuthor = $.trim($('#infoAuthor').val());
		
		if(infoTitle==""){infoTitle=null;
		
		}else{
			$('#user_dg').datagrid('load', {
				infoTitle : $('#infoTitle').val()
			});
		}
		/* 
       if(infoAuthor==""){infoAuthor=null;
		
		}else{
			$('#user_dg').datagrid('load', {
				infoAuthor : $('#infoAuthor').val()
			});
		} */
		
	}
	 
	//重新设置easy ui的时间格式
	$.fn.datebox.defaults.formatter=function(date){
		var y=date.getFullYear();
		var m=date.getMonth()+1;
		var d=date.getDate();
		return y+'/'+m+'/'+d;
	}
	$.fn.datebox.defaults.parser=function(date){
		if(date){
			return new Date(date)
		}else{
			return new Date();
		}
	}
	
	var url;
	function newUserMessage() {
		$('#user_dlg').dialog('open').dialog('setTitle', '新增');
		$('#user_fm').form('clear');//清除表单数据
		url = '${pageContext.request.contextPath}/admin/Info/addInfo.do';//新增调用的网址
	}
	function editUserMessage() {
		var row = $('#user_dg').datagrid('getSelected');
		if (row) {
			$('#user_dlg').dialog('open').dialog('setTitle', '编辑');
			$('#user_fm').form('clear');//清除表单数据
			$('#user_fm').form('load', row);
			url = '${pageContext.request.contextPath}/admin/Info/updateInfo.do?infoNo=' + row.infoNo;
		}
	}
	function saveUserMessage() {
		$('#user_fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#user_dlg').dialog('close'); // close the dialog
					$('#user_dg').datagrid('reload'); // reload the user data
				}
			}
		});
	}
	function destroyUserMessage() {
		var row = $('#user_dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
				if (r) {
					//ajax调用--异步通信调用
					$.post('${pageContext.request.contextPath}/admin/Info/deleteInfo.do', {
						infoNo : row.infoNo
					}, function(result) {
						if (result.success) {
							$('#user_dg').datagrid('reload'); // reload the user data
						} else {
							$.messager.show({ // show error message
								title : 'Error',
								msg : result.errorMsg
							});
						}
					}, 'json');//回调函数
				}
			});
		}
	}
</script>


</body>
</html>